$(document).ready(function() {
	var g = "/";
	var b = "m=api&c=user&a=status";
	window.getUserInfo = function() {
		$.ajax({
			url: g,
			data: b,
			type: "GET",
			dataType: "json",
			success: function(r) {
				if (!r.status) {
					return
				}
				var z = $("#userinfoContainer");
				var t = $("#usernameText");
				var q = $("#usernameShow");
				var A = $("#userId");
				var username_iMessage = $(".username-container .username-iMessage");
				var loginElement = $(".topbar-right a").eq(2);//2018-10-13新增关于解决隐藏登录元素
				q.html(r.name);
				A.html("(ID:" + r.id + ")");
				$("#serverCount").html(r.servercount);
				$("#orderCount").html(r.ordercount);
				$("#msgCount").html(r.msgcount);
				// username_iMessage.html(r.msgcount);
				if(r.msgcount > 0){
					username_iMessage.html(r.msgcount);
				}else{
					username_iMessage.remove();
				}
				var p = r.money || "0";
				if (String(p).indexOf(".") == -1) {
					p += ".00"
				}
				$("#userMoney").html(p);
				var x = $(".auth-status");
				var u = $(".new-auth");
				if (r.identityStatus == "1") {
					x.show();
					u.hide()
				} else {
					x.hide();
					u.show()
				}

				if(r.id){
					loginElement.hide();
					$(".apy-search-help").css('right','220px');
					$(".apy-china").css('right','125px');
					$(".login-coupon-reminder").remove();
				}

				z.addClass("welcome-user");
				var B = "userinfo-container--extend";
				var v = 300;
				var w = $("#usernameContainer");
				var s = $("#userPanel");
				var y = s.css("height");
				z.on("mouseenter", ".userinfo-container", function() {
					z.addClass(B);
					s.stop(true, false);
					s.css("height", 0);
					s.animate({
						height: y
					}, v)
				});
				z.on("mouseleave", ".userinfo-container", function() {
					s.stop(true, false);
					s.animate({
						height: 0
					}, v, function() {
						z.removeClass(B)
					})
				})
			}
		})
	};
	getUserInfo();
	var h = $("#toTop");
	h.hide();
	$(window).scroll(function() {
		if ($(window).scrollTop() > 100) {
			if (h.is(":hidden")) {
				h.stop().fadeIn(500)
			}
		} else {
			if (h.is(":visible")) {
				h.stop().fadeOut(500)
			}
		}
	});
	h.click(function() {
		$("body,html").stop().animate({
			scrollTop: 0
		}, 300);
		return false
	});
	var a = $(".header-nav>ul");
	$(".header-nav-li").mouseenter(function() {
		a.attr({
			"class": ""
		});
		// $(this).addClass("header-nav-li--active").siblings().removeClass("header-nav-li--active")
		$(this).addClass("header-nav-li--active").siblings().removeClass("header-nav-li--active")
	});
	$(".header-nav").mouseleave(function() {
		$(".header-nav-li").removeClass("header-nav-li--active");
		a.removeClass()
	});
	$(".pop-arrow").click(function() {
		$(this).parents(".header-nav-li").removeClass("header-nav-li--active")
	});
	var n = $(".header-container");
	var i = function() {
			if ($(window).outerWidth() < 1343) {
				n.addClass("narrow-screen")
			} else {
				n.removeClass("narrow-screen")
			}
		};
	i();
	$(window).resize(function() {
		i()
	});
	var m = null;
	$(".suspension-tel").mouseenter(function() {
		clearTimeout(m);
		$(this).addClass("active");
		$(this).children(".pop-detail").fadeIn(100)
	}).mouseleave(function() {
		var p = $(".pop-detail", $(this));
		var q = $(this);
		m = setTimeout(function() {
			if (!p.hasClass("active")) {
				q.removeClass("active");
				q.children(".pop-detail").fadeOut(100)
			}
		}, 200)
	});
	var l = null;
	$(".suspension-qrcode").mouseenter(function() {
		clearTimeout(l);
		$(this).addClass("active");
		$(this).children(".pop-detail").fadeIn(100)
	}).mouseleave(function() {
		var p = $(".pop-detail", $(this));
		var q = $(this);
		l = setTimeout(function() {
			if (!p.hasClass("active")) {
				q.removeClass("active");
				q.children(".pop-detail").fadeOut(100)
			}
		}, 200)
	});
	var k = null;
	$(".pop-detail", $(".suspension-tel")).mouseenter(function() {
		clearTimeout(k);
		$(this).addClass("active")
	}).mouseleave(function() {
		var p = $(this);
		k = setTimeout(function() {
			if (!p.parents("li").hasClass("active")) {
				p.hide()
			}
			p.removeClass("active")
		}, 200)
	});
	var j = null;
	$(".pop-detail", $(".suspension-qrcode")).mouseenter(function() {
		clearTimeout(j);
		$(this).addClass("active")
	}).mouseleave(function() {
		var p = $(this);
		j = setTimeout(function() {
			if (!p.parents("li").hasClass("active")) {
				p.hide()
			}
			p.removeClass("active")
		}, 200)
	});
	$(".weibo-logo").mouseenter(function() {
		$(".weibo").show()
	}).mouseleave(function() {
		$(".weibo").hide()
	});
	$(".weixin-logo").mouseenter(function() {
		$(".weixin").show()
	}).mouseleave(function() {
		$(".weixin").hide()
	});
	$("a[href='#a_null']").click(function() {
		return false
	});
	$(".link-banner").each(function() {
		var q = $(this);
		var p = q.data("url");
		if (p) {
			q.click(function() {
				var r = q.data("target") || "self";
				window.open(p, r)
			})
		}
	});
	if (window.PIE) {
		$(".pie-for-element").each(function() {
			PIE.attach(this)
		});
		$(".pie-for-children").children().each(function() {
			PIE.attach(this)
		});
		$(".pie-for-tree").find("*").each(function() {
			PIE.attach(this)
		})
	}
	var f = $(".show-captcha");
	var d = $(".refresh-captcha");
	var e = "/?m=api&c=captcha";
	var o = function() {
			return e + "&rnd=" + Math.random()
		};
	var c = function(p) {
			$(p).attr("src", o())
		};
	c(f);
	f.click(function() {
		c(this)
	});
	d.click(function() {
		c($(this).parent().find(".show-captcha"))
	});
	$(".help-content").click(function() {
		var p = $(this).data("content_id");
		$.cookie("helpIndex", p, {
			path: "/"
		});
		location.href = "/help/"
	})
});
$(function() {
	window.NY = window.NY || {};
	// if ($.dialog && $.dialog.tips) { //2018 10 20注释 关于解决NY.warn
	if ($.dialog ) {
		var DEFAULT_TIPS_SHOW_DURATION = 3;
		var tipsTypeList = ["success", "error", "loading"];
		var tipsTypeMap = {
			warn: "alert"
		};
		$.each(tipsTypeList, function(i, tipsType) {
			var basicMethodType = tipsTypeMap[tipsType] || tipsType;
			window.NY[tipsType] = function(text, duration, callback) {
				duration = duration || DEFAULT_TIPS_SHOW_DURATION;
				return $.dialog.tips(text, duration, basicMethodType, callback)
			}
		});
		NY.warn = function(text, callback) {
			$.dialog({
				title: "提示",
				content: '<div style="max-width: 510px;">' + text + "<div>",
				icon: "alert",
				close: callback
			})
		}
	}
	if (NY.warn) {
		NY.showBusy = function(callback) {
			return NY.warn("服务器繁忙，请稍后重试！", callback)
		}
	}
	if ($.dialog) {
		var loginHost = "/";
		var loginFrameURL = loginHost + "login/?type=frame";
		var loginActionURL = loginHost + "login/login.html";
		NY.showLoginDialog = function(loginSuccessCallback, dialogConfig) {
			var loginDialog = null;
			var defaultDialogConfig = {
				title: "会员登录",
				okVal: "登录",
				width: 500,
				height: 235,
				ok: function() {
					var iframe = this.iframe.contentWindow;
					var iframe_form = $(iframe.document).find("form");
					var param = {};
					iframe_form.find("[name]").each(function() {
						var $_input = $(this);
						param[$_input.prop("name")] = $_input.val()
					});
					$(".aui_state_highlight").prop({
						disabled: true
					});
					$.ajax({
						type: "post",
						url: loginActionURL,
						data: param,
						success: function(dataString) {
							$(".aui_state_highlight").prop({
								disabled: false
							});
							var responseData = (typeof dataString == "string") ? eval("(" + dataString + ")") : dataString;
							if (!responseData.result) {
								NY.warn(responseData.text);
								$(".show-captcha", iframe.document).click();
								return
							}
							loginDialog.close();
							loginSuccessCallback.call(loginDialog, responseData)
						},
						error: function() {
							$(".aui_state_highlight").prop({
								disabled: false
							});
							NY.showBusy()
						}
					});
					return false
				},
				cancel: true
			};
			delete dialogConfig.ok;
			var config = $.extend(defaultDialogConfig, dialogConfig);
			loginDialog = $.dialog.open(loginFrameURL, config);
			return loginDialog
		};
		NY.loginCheckThenDo = function(afterLoginCall, dialogConfig) {
			$.ajax({
				url: "/login/check.html",
				cache: false,
				dataType: "json",
				success: function(responseData) {
					if (!responseData.result) {
						if (responseData.isMobile) {
							location.href = "/login/";
							return false
						}
						var config = $.extend({
							okVal: "登录并确定"
						}, dialogConfig);
						NY.showLoginDialog(function(data) {
							if (!data.result) {
								NY.warn(data.text)
							} else {
								NY.success(data.text, 2, function() {
									afterLoginCall(false)
								})
							}
						}, config)
					} else {
						afterLoginCall(true)
					}
				},
				error: function() {
					NY.showBusy()
				}
			})
		}
	}
	NY.enterKey = function(element, handler, options) {
		options = options || {};
		var eventType = options.eventType || "keypress";
		var eventData = options.eventData;
		var isCtrlKey = options.isCtrlKey;
		var isShiftKey = options.isShiftKey;
		var isAltKey = options.isAltKey;
		var isBoolean = function(param) {
				return (typeof param === "boolean")
			};
		var myHandler = function(e) {
				var keyCode = e.which;
				var that = this;
				if ((keyCode == 10) || (keyCode == 13)) {
					if (isBoolean(isCtrlKey) && (isCtrlKey !== e.ctrlKey)) {
						return
					} else {
						if (isBoolean(isShiftKey) && (isShiftKey !== e.shiftKey)) {
							return
						} else {
							if (isBoolean(isAltKey) && (isAltKey !== e.altKey)) {
								return
							}
						}
					}
					handler.call(that, e)
				}
			};
		return $(element)[eventType](eventData, myHandler)
	};
	NY.ajax = function(url, options) {
		if (typeof url === "object") {
			options = url;
			url = undefined
		}
		var isShowWaitTip = (options.isShowWaitTip !== false);
		var settings = $.extend({
			url: url,
			type: "post",
			dataType: "json",
			error: function() {
				NY.showBusy()
			},
			complete: function(jqXHR, textStatus) {
				if (isShowWaitTip) {
					NY.hideWaiting()
				}
			}
		}, options);
		delete settings.isCoverSuccess;
		delete settings.successResultFalse;
		delete settings.isSuccessShowTip;
		delete settings.isSuccessJump;
		delete settings.isResultFalseWarn;
		delete settings.waitText;
		delete settings.isShowWaitTip;
		delete settings.isShowWaitMask;
		delete settings.waitMaskStyle;
		if (options.isCoverSuccess !== true) {
			settings.success = function(responseData, textStatus, jqXHR) {
				var context = this;
				var responseDataText;
				var responseDataTime = responseData.time;
				if (responseData.result) {
					responseDataText = responseData.text || "操作成功"
				} else {
					responseDataText = responseData.text || "操作失败"
				}
				if (!responseData.result) {
					var resultFalseHandler = function() {
							var successResultFalse = options.successResultFalse;
							if ($.isFunction(successResultFalse)) {
								successResultFalse.call(context, responseData, textStatus, jqXHR)
							}
						};
					if (options.isResultFalseWarn !== false) {
						NY.warn(responseDataText, function() {
							resultFalseHandler()
						})
					} else {
						resultFalseHandler()
					}
					return
				}
				var successHandler = function() {
						var optionSuccess = options.success;
						var isJumpAfterCall = true;
						if ($.isFunction(optionSuccess)) {
							isJumpAfterCall = optionSuccess.call(context, responseData, textStatus, jqXHR)
						}
						if ((options.isSuccessJump !== false) && (isJumpAfterCall !== false)) {
							if (responseData.url) {
								window.location.href = responseData.url
							} else {
								if (responseData.reload) {
									window.location.reload()
								}
							}
						}
					};
				if ((options.isSuccessShowTip !== false) && responseDataText) {
					NY.success(responseDataText, responseDataTime, function() {
						successHandler()
					})
				} else {
					successHandler()
				}
			}
		}
		if (isShowWaitTip) {
			NY.waiting(options.waitText, options.isShowWaitMask)
		}
		return $.ajax(settings)
	};
	NY.getHash = function(hashName) {
		var reg = new RegExp("(^|&)" + hashName + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return unescape(r[2])
		}
		return ""
	}


});
$(function() {
	var e = function(f) {
			document.cookie = f + "=;path=/;expires=" + (new Date().toUTCString())
		};
	var d = location.hash.slice(1);
	var a = d.match(/(\-\d+)/g);
	if (!a || (a.length > 2)) {
		return
	}
	var b = (a[0] || "").slice(1);
	var c = (a[1] || "").slice(1);
	if (!c) {
		c = b;
		e("channelType")
	} else {
		document.cookie = "channelType=" + b + ";path=/"
	}
	document.cookie = "channelID=" + c + "; path=/"
});

function randomNum(b) {
	var a = "";
	for (var c = 0; c < b; c++) {
		var d = "" + Math.floor(Math.random() * 10);
		a += d
	}
	return a
}

